package middol.enums

import grails.util.Holders
import middol.constants.i18n.CommonConstants
import middol.utils.LangService
import org.springframework.beans.factory.annotation.Autowired

/**
* @Description:    返回结果枚举
* @Author:         zhangjiayu@middol.com
* @CreateDate:     2020/3/19 11:01
* @Version:        1.0
*/
enum ResultCodeEnum {
    /**
     * 成功
     */
    OK("200", "OK"),

    /**
     * 通用参数错误
     */
    AUTH_ERROR("401", "AUTH_ERROR"),
    /**
     * 通用参数错误
     */
    VALIDATE_ERROR("422", "VALIDATE_ERROR"),
    /**
     *  数据不存在
     */
    NOTFOUND("432", "NOTFOUND"),

    /**
     * 通用参数错误
     */
    ERROR("500", "ERROR"),

    /**
     * 系统异常
     */
    SYSTEM_ERROR("501", "SYSTEM_ERROR"),

    /**
     * 获取结果异常
     */
    RESULT_NULL("10002","RESULT_NULL"),

    /**
     * 参数为空
     */
    NO_ARGS("20000", "NO_ARGS"),

    /**
     * 非法参数
     */
    ARGS_ERROR("20001","ARGS_ERROR"),

    /**
     * 没有访问权限
     */
    NO_AUTH("403", "NO_AUTH");

    private String code
    private String msg

    LangService langService = Holders.grailsApplication.mainContext.getBean(LangService.class)

    ResultCodeEnum(String code, String msg) {
        this.code = code
        this.msg = msg
    }

    String getCode() {
        return code
    }

    void setCode(String code) {
        this.code = code
    }

    String getMsg() {
        return langService.getMessage(CommonConstants.Status_PROFIX + msg)
    }

    void setMsg(String msg) {
        this.msg = msg
    }
}